<?php
/**
 * Smarty plugin
 * @category VaselinEngine
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty {tinymce} function plugin
 *
 * Type:     function<br>
 * Name:     tinymce<br>
 * Purpose:  print out a tinymce WYSIWYG editor. Used by Bel_Forms_Builder but could be used everywhere
 * @author Konstantin Shamko <konstantin.shamko@gmail.com>
 * @param array parameters
 * @param Smarty
 * @return string|null
 */
function smarty_function_tinymce($params, &$smarty) {

	$width  = isset($params['width']) ? (int) $params['width'] : 400;
	$height = isset($params['height']) ? (int) $params['height'] : 300;
	$text   = isset($params['value']) ? trim($params['value']) : '';
	$name   = isset($params['name']) ? trim($params['name']) : 'editor';	

	print '	
	<script type="text/javascript">
	tinyMCE.init({
		mode : "exact",
		elements: "'.$name.'",
		theme : "advanced",
		width : "'.$width.'",
		height : "'.$height.'",
		plugins: "ibrowser",
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,sub,sup,separator,formatselect",
		theme_advanced_buttons2 : "bullis,numlist,separator,outdent,indent,separator,undo,redo,separator,link,unlink,separator,ibrowser,charmap,hr,code",
		theme_advanced_buttons3 : "fontselect,fontsizeselect,forecolor,backcolor,removeformat",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		force_br_newlines : true,
        forced_root_block : "",
        extended_valid_elements : "form[name|id|action|method|enctype|accept-charset|onsubmit|onreset|target],input[id|name|type|value|size|maxlength|checked|accept|s rc|width|height|disabled|readonly|tabindex|accessk ey|onfocus|onblur|onchange|onselect],textarea[id|name|rows|cols|disabled|readonly|tabindex|acces skey|onfocus|onblur|onchange|onselect],option[name|id|value],select[id|name|type|value|size|maxlength|checked|accept|s rc|width|height|disabled|readonly|tabindex|accessk ey|onfocus|onblur|onchange|onselect|length|options |selectedIndex]"
	});
	</script>
	<textarea name="'.$name.'" id="'.$name.'">'.$text.'</textarea>	
	';
}